package traveler.activities;

import traveler.controllers.GoogleMapsController;
import traveler.controllers.StepController;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

public class QRCodeActivity extends Activity
{
	private Bundle _bundle;
	
	public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
        startActivityForResult(intent, 0);
        
    }
	
	public void onActivityResult(int requestCode, int resultCode, Intent intent)
	{
	   if (requestCode == 0)
	   {
	      if (resultCode == RESULT_OK)
	      {
	         String contents = intent.getStringExtra("SCAN_RESULT");
	         String[] args = contents.split(";");
	         
	         if(args.length == 3)
	         {
	        	 _bundle = new Bundle();

	        	 _bundle.putInt(GoogleMapsController.LATITUDE, (int)(Float.parseFloat(args[0]) * 1e6));
	        	 _bundle.putInt(GoogleMapsController.LONGITUDE, (int)(Float.parseFloat(args[1]) * 1e6));
	        	 _bundle.putString(StepController.QUESTION, args[2]);
	        	 
	        	 intent = new Intent(this, GoogleMapsActivity.class);
	        	 intent.putExtras(_bundle);
	        	 
	        	 startActivity(intent);
	         }
	      }
	   }
	}
}
